Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

deFileSystem_priv.hpp

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////////////
00002 /// @file deFileSystem.hpp
00003 ///
00004 /// @brief private base file system interface header
00005 ///
00006 /// @author Lightning
00007 ///
00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
00009 /// contents of this file is subject to the Destiny3D Member License which
00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
00011 ///
00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
00014 /// for any particular purpose.
00015 ///
00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
00017 ///
00018 /// <hr>
00019 ///                                 Change History
00020 /// <hr>
00021 ///
00022 /// @date Nov 2001
00023 /// @author Lightning
00024 /// @remarks Creation
00025 ///
00026 /// @date Dec 2002
00027 /// @author kurifu
00028 /// @remarks File finding handles
00029 ///
00030 ///////////////////////////////////////////////////////////////////////////////
00031 
00032 #ifndef DE_FILESYSTEM_PRIV_HPP
00033 #define DE_FILESYSTEM_PRIV_HPP
00034 
00035 #ifdef _WIN32
00036 #include <windows.h>
00037 #elif linux
00038 #include <dirent.h>
00039 #endif
00040 
00041 #include "deFileSystem.hpp"
00042 
00043 class deFileSystem;
00044 class deFSReal;
00045 class deFSVirtual;
00046 
00047 //base class for all filesystems
00048 class deFileSystem : virtual public IdeFileSystem, public deRefCountBase
00049 {
00050 protected:
00051     deFileSystem();
00052     virtual ~deFileSystem();
00053 public:
00054 
00055     void* GetInterface(IdeFileSystem::interface_t i);
00056 
00057     virtual IdeFile* Open(const char *Filename, long OpenFlags);
00058 
00059     //get/set the current directory
00060     virtual const char *GetDirectory();
00061     virtual deBoolean SetDirectory(const char *Directory);
00062     
00063     //allow for renaming, deleting, moving, and copying of files
00064     virtual deBoolean Rename(const char *OldFilename, const char *NewFilename);
00065     virtual deBoolean Delete(const char *Filename, deFSPROGRESS StatusCallback);
00066     virtual deBoolean Move(const char *OldFilename, const char *NewFilename, deFSPROGRESS StatusCallback);
00067     virtual deBoolean Copy(const char *OldFilename, const char *NewFilename, deFSPROGRESS StatusCallback);
00068 
00069     //create and delete directories
00070     virtual deBoolean AddDirectory(const char *Directory);
00071     virtual deBoolean DeleteDirectory(const char *Directory, deFSPROGRESS StatusCallback);
00072 
00073     //allow finding of files
00074     void* FindFirst(const char *Pattern, deFileProperties *Properties);
00075     deBoolean FindNext(void* Handle, deFileProperties *Properties);
00076     deBoolean FindEnd(void* Handle);
00077 };
00078 
00079 //class for the real FS
00080 class deFSReal : public deFileSystem, public IdeFSReal
00081 {
00082 protected:
00083     //allow the real class to call the open
00084     friend class deFileReal;
00085 
00086     //allow opening a file from deFileReal
00087     deBoolean deFSReal::Open(deFileReal *RealFile, const char *Filename, long OpenFlags);
00088 
00089 public:
00090     deFSReal();
00091     ~deFSReal();
00092 
00093     void* GetInterface(IdeFileSystem::interface_t i);
00094 
00095     IdeFile* Open(const char *Filename, long OpenFlags);
00096 
00097     //get/set the current directory
00098     const char *GetDirectory();
00099     deBoolean SetDirectory(const char *Directory);
00100     
00101     //allow for renaming, deleting, moving, and copying of files
00102     deBoolean Rename(const char *OldFilename, const char *NewFilename);
00103     deBoolean Delete(const char *Filename, deFSPROGRESS StatusCallback);
00104     deBoolean Move(const char *OldFilename, const char *NewFilename, deFSPROGRESS StatusCallback);
00105     deBoolean Copy(const char *OldFilename, const char *NewFilename, deFSPROGRESS StatusCallback);
00106 
00107     //create and delete directories
00108     deBoolean AddDirectory(const char *Directory);
00109     deBoolean DeleteDirectory(const char *Directory, deFSPROGRESS StatusCallback);
00110     
00111     //allow finding of files
00112     void* FindFirst(const char *Pattern, deFileProperties *Properties);
00113     deBoolean FindNext(void* Handle, deFileProperties *Properties);
00114     deBoolean FindEnd(void* Handle);
00115 
00116 private:
00117     char            priv_CurrentDirectory[1024];        //current directory
00118     char            priv_TempCurrentDirectory[1024];    //tempory place for directory changing
00119 
00120     #define         RealFindID          0x44494652      //'RFID', id for search handles
00121 
00122     typedef struct FindInfoReal
00123     {
00124         DWORD               FindID;                     //stucture ID
00125 #ifdef WIN32
00126         HANDLE              FindHandle;                 //handle to the data
00127         WIN32_FIND_DATA     FindData;                   //dos returned find data
00128         
00129 #elif linux
00130       DIR * FindDir;
00131       char * Pattern;
00132 #else
00133 #error FindData not implemented for OS
00134 #endif
00135     } FindInfoReal;
00136 };
00137 
00138 //class for the virtual fs
00139 class deFSVirtual : public deFileSystem, public IdeFSVirtual
00140 {
00141 public:
00142     deFSVirtual();
00143     ~deFSVirtual();
00144 
00145     void* GetInterface(IdeFileSystem::interface_t i);
00146 
00147     //functions to open/close the base file
00148     deBoolean OpenBaseFile(IdeFile *BaseFile, long OpenFlags);
00149     deBoolean OpenBaseFilename(const char *Filename, long OpenFlags);
00150     deBoolean CloseBaseFile();
00151 
00152     //functions to open a virtual file
00153     IdeFile* Open(const char *Filename, long OpenFlags);
00154 
00155     //get/set the current directory
00156     const char *GetDirectory();
00157     deBoolean SetDirectory(const char *Directory);
00158     
00159     //allow for renaming, deleting, moving, and copying of files
00160     deBoolean Rename(const char *OldFilename, const char *NewFilename);
00161     deBoolean Delete(const char *Filename, deFSPROGRESS StatusCallback);
00162     deBoolean Move(const char *OldFilename, const char *NewFilename, deFSPROGRESS StatusCallback);
00163     deBoolean Copy(const char *OldFilename, const char *NewFilename, deFSPROGRESS StatusCallback);
00164 
00165     //create and delete directories
00166     deBoolean AddDirectory(const char *Directory);
00167     deBoolean DeleteDirectory(const char *Directory, deFSPROGRESS StatusCallback);
00168     
00169     //allow finding of files
00170     void* FindFirst(const char *Pattern, deFileProperties *Properties);
00171     deBoolean FindNext(void* Handle, deFileProperties *Properties);
00172     deBoolean FindEnd(void* Handle);
00173 
00174 protected:
00175     friend class deFileVirtual;
00176 
00177     //structure containing information about the files in the VFS
00178     #pragma pack(push,4)        //Because of how the file is read, we need 4 byte packing instead of 8
00179     typedef struct VirtualFileEntry
00180     {
00181         char *      FileName;                           //file's name
00182         union
00183         {
00184             long                        Position;       //position in the VFS that the file exists
00185             struct VirtualFileEntry *   NextDirectory;  //next sub directory for the parent directory
00186         };
00187         union
00188         {
00189             long                        Size;           //size of the file
00190             struct VirtualFileEntry *   SubDirectory;   //pointer to the sub directories for the current directory
00191 
00192         };
00193         s64                         Time;               //time of the file
00194         struct VirtualFileEntry *   NextFile;           //pointer to the next file for the current directory
00195         struct VirtualFileEntry *   ParentDirectory;    //pointer to the parent of the file or directory
00196         deFileVirtual *             OpenedFile;         //pointer to the class that has the file if it is open
00197     } VirtualFileEntry;
00198     #pragma pack(pop)           //restore the packing
00199     
00200     //function to open up a virtual file from IdeFileVirtual
00201     deBoolean Open(deFileVirtual *BaseFile, const char *Filename, long OpenFlags);
00202 
00203     //all the private functions that deFileVirtual will call
00204     deBoolean Close(deFileVirtual *FileEntry);
00205     
00206     //read/write data
00207     long Read(deFileVirtual *FileEntry, void *Buffer, long Length);
00208     long Write(deFileVirtual *FileEntry, void *Buffer, long Length);
00209 
00210     //set a file's length
00211     DWORD deFSVirtual::SetSize(deFileVirtual *FileEntry, long NewSize, deFSPROGRESS *StatusCallback);
00212 
00213 private:
00214     //private functions to read and write directories to the file
00215     deBoolean ReadDirectoryTree();
00216     deBoolean WriteDirectoryTree();
00217     deBoolean DestroyDirectoryTree();
00218 
00219     //private function for moving data around in the VFS
00220     DWORD AdjustFile(deFileVirtual *FileEntry,long WriteSize, deBoolean MakeCopy, deFSPROGRESS *StatusCallback);
00221     DWORD MoveData(long StartPosition, long ByteShift, deFSPROGRESS *StatusCallback);
00222 
00223     //pattern matching function
00224     deBoolean MatchPattern(const char *Pattern, const char *Filename);
00225     deBoolean IsPattern(const char *Pattern);
00226 
00227     //internal DeleteDirectory that has a pointer to the function pointer
00228     DWORD deFSVirtual::DeleteDirectory(const char *Directory, deFSPROGRESS *StatusCallback);
00229 
00230     #define VirtualFindID       0x44494656      //'VFID', id for search handles
00231     
00232     //header structure in the file
00233     typedef struct VirtualHeader
00234     {
00235         DWORD   ID;                 //ID verifying this is our file
00236         DWORD   Version;            //Version of the file
00237         long    DirectoryOffset;    //offset to the list of directories and files
00238     } VirtualHeader;
00239 
00240     //a struct to keep all the find information together
00241     typedef struct FindInfoVirtual
00242     {
00243         DWORD               FindID;             //so we know we have the right struct
00244         char *              FindPattern;        //the pattern currently being looked for
00245         VirtualFileEntry *  FindLastEntry;      //last entry find returned
00246         VirtualFileEntry *  FindDirectory;      //the directory we are doing the find in
00247         deBoolean           FindDirSearched;    //where directories searched yet
00248     } FindInfoVirtual;
00249 
00250     //directory parsing/navigating function
00251     //I am unsure why, but a typedef struct for VirtualFileEntry was causing compile errors so the function
00252     //is defined here to stop the errors
00253     VirtualFileEntry *ParseDirectory(const char *Directory, deBoolean FileAttached, long *FileNameStart);
00254     deBoolean NameInUse(VirtualFileEntry *Directory, const char *Name, deBoolean *IsDirectory);
00255     deBoolean AdjustFilePositions(VirtualFileEntry *Directory, long StartPosition, long ByteShift);
00256 
00257     //data about the base fs used to read/write files
00258     IdeFSReal *         BaseFS;         //a base FS if we opened up a real fs
00259     IdeFile *           BaseFile;       //the file to use to read/write the virtual fs data
00260     deBoolean           BaseFileOwner;  //did we open/create the base file
00261     long                BaseFlags;      //flags for the base file system to know if we can write files
00262 
00263     //storage of the directory tree
00264     VirtualFileEntry *  RootDirectory;      //pointer to the root directory
00265     VirtualFileEntry *  CurrentDirectory;   //pointer to the current directory entry
00266 
00267     //a temporary variable storing the current directory name
00268     char *              CurDirectoryName;
00269 };
00270 
00271 #endif
00272 

Generated on Mon Sep 12 19:58:27 2005 for Destiny3D by doxygen1.3-rc3